package net.esj.basic.core.engine.template.impl;

import java.io.Writer;
import java.util.Map;

import net.esj.basic.core.engine.template.AbstractTemplate;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

public class VelocityTemplate implements AbstractTemplate {

	private Template template;
	
	public VelocityTemplate(Template template) {
		super();
		this.template = template;
	}

	public Template getTemplate() {
		return template;
	}

	public void setTemplate(Template template) {
		this.template = template;
	}

	@Override
	public String getEngineType() {
		return "velocity";
	}

	@Override
	public void process(Object context, Writer writer) throws Exception{
		VelocityContext vc = new VelocityContext((Map) context);
		template.merge(vc, writer);
	}

}
